<?php
function alert($flag,$data){
    echo json_encode(array('flag'=>$flag,'data'=>$data));
    exit;
}
function email($email){
    $pattern="/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i";
    if(preg_match($pattern,$email)){
        return true;
    }
    return false;
}
function push($url,$post_data){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_TIMEOUT,60);//单位秒,也可以使用
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_data));
    $output = curl_exec($ch);
    curl_close($ch);
    return trim($output,'﻿');//替换掉utf8 BOM格式编码字符
}
function send_curl($url,$data){
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	 curl_setopt($ch, CURLOPT_TIMEOUT,60);//单位秒,也可以使用
     //post传值数据
     curl_setopt($ch, CURLOPT_POST, 1);
     //post的变量
     curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('data'=>json_encode($data))));
     $output = curl_exec($ch);

     curl_close($ch);
     return trim($output,'﻿');//替换掉utf8 BOM格式编码字符
 }
//////权限检查  有则显示对应的按钮，没有则不显示
function root($a,$c=CONTROLLER_NAME){
    $root=session('user_root');
    $is_root = 0;
    foreach ($root as $k => $v) {
        if ($k == $c && in_array($a, $v)) {
            $is_root = 1;
        }
    }
    if ($is_root==0) {
        $no_arr = array(//额外的都具备的权限
            'Index' => array('index', 'welcome'),
            'Unit' => array('getUnit'),
            'Category' => array('getCategory'),
            'Role' => array('getRole', 'getEditRole'),
            'List' => array('warehouse_select_session_delete', 'warehouse_select'),
        );
        foreach($no_arr as $k=>$v){
            if($k == $c && in_array($a, $v)){
                $is_root=1;
            }
        }
        if($is_root==1){
            return 1;
        }else{
            return 0;
        }
    }
}